package com.changgou.search.controller;

import com.changgou.search.service.SkuService;
import com.changgou.util.Result;
import com.changgou.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/*****
 * @Author: 黑马训练营
 * @Description: com.changgou.search.controller
 ****/
@RestController
@CrossOrigin
@RequestMapping(value = "/search")
public class SkuController {

    @Autowired
    private SkuService skuService;


    /***
     * 数据搜索实现
     */
    @GetMapping
    public Map search(@RequestParam(required = false) Map<String,String> searchMap){
        return skuService.search(searchMap);
    }

    /***
     * 批量导入数据到ES中
     */
    @GetMapping(value = "/import")
    public Result importData(){
        //调用Service导入数据
        skuService.importSku();
        return new Result(true, StatusCode.OK,"导入数据成功！");
    }
}
